package cn.lystudio.rohmtimeopwide_background_v11.service.impl;

import cn.dev33.satoken.stp.StpUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.ListUtil;
import cn.hutool.core.convert.Convert;
import cn.lystudio.rohmtimeopwide_background_v11.entity.dto.DTree;
import cn.lystudio.rohmtimeopwide_background_v11.entity.po.DepartmentsPO;
import cn.lystudio.rohmtimeopwide_background_v11.entity.po.MachinePO;
import cn.lystudio.rohmtimeopwide_background_v11.mapper.DepartmentsPOMapper;
import cn.lystudio.rohmtimeopwide_background_v11.mapper.MachinePOMapper;
import cn.lystudio.rohmtimeopwide_background_v11.service.DTreeService;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
@Slf4j
@DS("master")

public class DTreeServiceImpl implements DTreeService {
    @Resource
    private DepartmentsPOMapper departmentsPOMapper;
    @Resource
    private MachinePOMapper machinePOMapper;

    @Override
    public List<DTree> getAll(Boolean forHomePage) {
        List<DTree> dTreeList = CollUtil.list(false);
        // 1.获取当前用户所有第一级制造部
        List<String> topDeptPermisList=CollUtil.list(false);
        // 给主页时,需要
        // 给负1页时,不需要
        if(forHomePage){
            topDeptPermisList = StpUtil.getPermissionList(StpUtil.getLoginIdAsString());
            if(topDeptPermisList.size()!=1) return null;

        }

        LambdaQueryWrapper<DepartmentsPO> wrapper = new QueryWrapper<DepartmentsPO>().lambda();
        if(forHomePage){
            wrapper//.eq(DepartmentsPO::getEnabled,true)
                    .eq(DepartmentsPO::getParentID,0)   //父ID=0
                    .ge(DepartmentsPO::getDepartmentID,10)      //自己的ID>10
                    // 非超级管理员
                    .eq(Convert.toInt(topDeptPermisList.get(0))>=10 ,DepartmentsPO::getDepartmentID,topDeptPermisList.get(0))
                    .orderByAsc(DepartmentsPO::getDepartmentName);
        } else {
            wrapper//.eq(DepartmentsPO::getEnabled,true)
                    .eq(DepartmentsPO::getParentID,0)   //父ID=0
                    .ge(DepartmentsPO::getDepartmentID,10)      //自己的ID>10
                    .orderByAsc(DepartmentsPO::getDepartmentName);
        }

        List<DepartmentsPO> topDeptList = departmentsPOMapper.selectList(wrapper);
        if(CollUtil.isEmpty(topDeptList)) return null;
        List<Integer> topDeptIDList = CollUtil.list(false);
        CollUtil.forEach(topDeptList,(topDeptPO,index)->{
            topDeptIDList.add(topDeptPO.getDepartmentID());
        });
        // 2.获取所有的第二级制造工程
        LambdaQueryWrapper<DepartmentsPO> wrapper2 = new QueryWrapper<DepartmentsPO>().lambda();
        wrapper2.in(DepartmentsPO::getParentID,topDeptIDList);
        List<DepartmentsPO> secDeptList = departmentsPOMapper.selectList(wrapper2);
        if(CollUtil.isEmpty(secDeptList)) return null;
        List<Integer> secDeptIDList = CollUtil.list(false);
        CollUtil.forEach(secDeptList.iterator(),(secDeptPO,index2)->{
            secDeptIDList.add(secDeptPO.getDepartmentID());
        });
        //3.获取所有的设备
        LambdaQueryWrapper<MachinePO> wrapper3 = new LambdaQueryWrapper<>();
        wrapper3.in(MachinePO::getSecDeptID,secDeptIDList);
        List<MachinePO> machineList = machinePOMapper.selectList(wrapper3);
        if(CollUtil.isEmpty(machineList)) return null;

        //4.组装数据
        CollUtil.forEach(topDeptList.iterator(),(topDeptPO,index)->{
            DTree dTree = new DTree();
            // 4.1 第一层,制造部数据
            dTree.setId(topDeptPO.getDepartmentID().toString());
            dTree.setParentId("0");
            dTree.setTitle(topDeptPO.getDepartmentName());
            dTree.setLast(false);
            dTree.setDisabled(!topDeptPO.getEnabled());
            // 4.2 第二层
            List<DTree> dTreeList4SecDept = CollUtil.list(false);
            CollUtil.forEach(secDeptList.iterator(),(secDeptPO,index2)->{
                if(topDeptPO.getDepartmentID().equals(secDeptPO.getParentID())){
                    DTree dTree4SecDept = new DTree();
                    dTree4SecDept.setId(secDeptPO.getDepartmentID().toString());
                    dTree4SecDept.setParentId(topDeptPO.getDepartmentID().toString());
                    dTree4SecDept.setTitle(secDeptPO.getDepartmentName());
                    dTree4SecDept.setLast(false);
                    dTree4SecDept.setDisabled(!secDeptPO.getEnabled());
                    //4.3 第三层
                    List<DTree> dTreeList4Machine = CollUtil.list(false);
                    CollUtil.forEach(machineList.iterator(),(machinePO,index3)->{
                        if(secDeptPO.getDepartmentID().equals(machinePO.getSecDeptID())){
                            DTree dTree4Machine = new DTree();
                            dTree4Machine.setId(machinePO.getMachineID().toString());
                            dTree4Machine.setParentId(secDeptPO.getDepartmentID().toString());
                            dTree4Machine.setTitle(machinePO.getMachineNo());
                            dTree4Machine.setLast(true);
                            dTree4Machine.setDisabled(!machinePO.getEnabled());
                            dTreeList4Machine.add(dTree4Machine);
                        }
                    });
                    List<DTree> orderDTreeList4Machine = ListUtil.sortByProperty(dTreeList4Machine, "title");
                    dTree4SecDept.setChildren(orderDTreeList4Machine);

                    dTreeList4SecDept.add(dTree4SecDept);
                }
            });
            dTree.setChildren(dTreeList4SecDept);

            dTreeList.add(dTree);
        });
        //5.过滤数据
        CollUtil.forEach(dTreeList.iterator(),(dTree,index)->{
            if(CollUtil.isEmpty(dTree.getChildren())) {
                dTree.setLast(true);
                dTree.setDisabled(true);
            } else {
                CollUtil.forEach(dTree.getChildren().iterator(),(dTree4SecDept,index2)->{
                    if(CollUtil.isEmpty(dTree4SecDept.getChildren())){
                        dTree4SecDept.setLast(true);
                        dTree4SecDept.setDisabled(true);
                    }
                });
            }
        });

        return dTreeList;
    }

    @Override
    public List<DTree> getAllSecDept() {
        List<DTree> dTreeList = CollUtil.list(false);
        // 1.获取所有第一级制造部
        LambdaQueryWrapper<DepartmentsPO> wrapper = new LambdaQueryWrapper<>();
        wrapper//.eq(DepartmentsPO::getEnabled,true)
            .eq(DepartmentsPO::getParentID,0)   //父ID=0
            .ge(DepartmentsPO::getDepartmentID,10)      //自己的ID>10
            .orderByAsc(DepartmentsPO::getDepartmentName);
        List<DepartmentsPO> topDeptList = departmentsPOMapper.selectList(wrapper);
        if(CollUtil.isEmpty(topDeptList)) return null;
        // 1.1 将所有的第一级制造部ID存入List
        List<Integer> topDeptIDList = CollUtil.list(false);
        CollUtil.forEach(topDeptList,(topDeptPO,index)->{
            topDeptIDList.add(topDeptPO.getDepartmentID());
        });
        // 2.获取所有的第二级制造工程
        LambdaQueryWrapper<DepartmentsPO> wrapper2 = new QueryWrapper<DepartmentsPO>().lambda();
        wrapper2.in(DepartmentsPO::getParentID,topDeptIDList);
        List<DepartmentsPO> secDeptList = departmentsPOMapper.selectList(wrapper2);
        if(CollUtil.isEmpty(secDeptList)) return null;
        // 3.组装数据
        CollUtil.forEach(topDeptList.iterator(),(topDeptPO,index)->{
            DTree dTree = new DTree();
            // 4.1 第一层,制造部数据
            dTree.setId(topDeptPO.getDepartmentID().toString());
            dTree.setParentId("0");
            dTree.setTitle(topDeptPO.getDepartmentName());
            dTree.setLast(false);
            dTree.setDisabled(!topDeptPO.getEnabled());
        });
        //4.组装数据
        CollUtil.forEach(topDeptList.iterator(),(topDeptPO,index)->{
            DTree dTree = new DTree();
            // 4.1 第一层,制造部数据
            dTree.setId(topDeptPO.getDepartmentID().toString());
            dTree.setParentId("0");
            dTree.setTitle(topDeptPO.getDepartmentName());
            dTree.setLast(false);
            dTree.setDisabled(!topDeptPO.getEnabled());
            // 4.2 第二层
            List<DTree> dTreeList4SecDept = CollUtil.list(false);
            CollUtil.forEach(secDeptList.iterator(),(secDeptPO,index2)->{
                if(topDeptPO.getDepartmentID().equals(secDeptPO.getParentID())){
                    DTree dTree4SecDept = new DTree();
                    dTree4SecDept.setId(secDeptPO.getDepartmentID().toString());
                    dTree4SecDept.setParentId(topDeptPO.getDepartmentID().toString());
                    dTree4SecDept.setTitle(secDeptPO.getDepartmentName());
                    dTree4SecDept.setLast(false);
                    dTree4SecDept.setDisabled(!secDeptPO.getEnabled());
                    dTreeList4SecDept.add(dTree4SecDept);
                }
            });
            dTree.setChildren(dTreeList4SecDept);
            dTreeList.add(dTree);
        });

        //5.过滤数据
        CollUtil.forEach(dTreeList.iterator(),(dTree,index)->{
            if(CollUtil.isEmpty(dTree.getChildren())) {
                dTree.setLast(true);
                dTree.setDisabled(true);
            }
            else {
                CollUtil.forEach(dTree.getChildren().iterator(),(dTree4SecDept,index2)->{
                    if(CollUtil.isEmpty(dTree4SecDept.getChildren())){
                        dTree4SecDept.setLast(true);
                        dTree4SecDept.setDisabled(false);
                    }
                });
            }
        });

        return dTreeList;
    }

    @Override
    public List<DTree> getAll4UsmZl() {
        List<DTree> dTreeList = CollUtil.list(false);
        // 1.获取所有第一级制造部
        List<String> topDeptPermisList=CollUtil.list(false);
        topDeptPermisList = StpUtil.getPermissionList(StpUtil.getLoginIdAsString());
        if(topDeptPermisList.size()!=1) return null;
        if((!topDeptPermisList.get(0).equals("144")) && (!topDeptPermisList.get(0).equals("1")))
            return null;


        LambdaQueryWrapper<DepartmentsPO> wrapper = new QueryWrapper<DepartmentsPO>().lambda();

        wrapper .eq(DepartmentsPO::getParentID,0)   //父ID=0
                .eq(DepartmentsPO::getDepartmentID,144)      //自己的ID>10
                .orderByAsc(DepartmentsPO::getDepartmentName);

        List<DepartmentsPO> topDeptList = departmentsPOMapper.selectList(wrapper);
        if(CollUtil.isEmpty(topDeptList)) return null;
        List<Integer> topDeptIDList = CollUtil.list(false);
        CollUtil.forEach(topDeptList,(topDeptPO,index)->{
            topDeptIDList.add(topDeptPO.getDepartmentID());
        });

        // 2.获取所有的第二级制造工程
        LambdaQueryWrapper<DepartmentsPO> wrapper2 = new QueryWrapper<DepartmentsPO>().lambda();
        wrapper2.in(DepartmentsPO::getParentID,topDeptIDList);
        List<DepartmentsPO> secDeptList = departmentsPOMapper.selectList(wrapper2);
        if(CollUtil.isEmpty(secDeptList)) return null;
        List<Integer> secDeptIDList = CollUtil.list(false);
        CollUtil.forEach(secDeptList.iterator(),(secDeptPO,index2)->{
            secDeptIDList.add(secDeptPO.getDepartmentID());
        });

        //3.获取所有的设备
        LambdaQueryWrapper<MachinePO> wrapper3 = new LambdaQueryWrapper<>();
        wrapper3.in(MachinePO::getSecDeptID,secDeptIDList);
        List<MachinePO> machineList = machinePOMapper.selectList(wrapper3);
        if(CollUtil.isEmpty(machineList)) return null;

        //4.组装数据
        CollUtil.forEach(topDeptList.iterator(),(topDeptPO,index)->{
            DTree dTree = new DTree();
            // 4.1 第一层,制造部数据
            dTree.setId(topDeptPO.getDepartmentID().toString());
            dTree.setParentId("0");
            dTree.setTitle(topDeptPO.getDepartmentName());
            dTree.setLast(false);
            dTree.setDisabled(!topDeptPO.getEnabled());
            // 4.2 第二层
            List<DTree> dTreeList4SecDept = CollUtil.list(false);
            CollUtil.forEach(secDeptList.iterator(),(secDeptPO,index2)->{
                if(topDeptPO.getDepartmentID().equals(secDeptPO.getParentID())){
                    DTree dTree4SecDept = new DTree();
                    dTree4SecDept.setId(secDeptPO.getDepartmentID().toString());
                    dTree4SecDept.setParentId(topDeptPO.getDepartmentID().toString());
                    dTree4SecDept.setTitle(secDeptPO.getDepartmentName());
                    dTree4SecDept.setLast(false);
                    dTree4SecDept.setDisabled(!secDeptPO.getEnabled());
                    //4.3 第三层
                    List<DTree> dTreeList4Machine = CollUtil.list(false);
                    CollUtil.forEach(machineList.iterator(),(machinePO,index3)->{
                        if(secDeptPO.getDepartmentID().equals(machinePO.getSecDeptID())){
                            DTree dTree4Machine = new DTree();
                            dTree4Machine.setId(machinePO.getMachineID().toString());
                            dTree4Machine.setParentId(secDeptPO.getDepartmentID().toString());
                            dTree4Machine.setTitle(machinePO.getMachineNo());
                            dTree4Machine.setLast(true);
                            dTree4Machine.setDisabled(!machinePO.getEnabled());
                            dTreeList4Machine.add(dTree4Machine);
                        }
                    });
                    dTree4SecDept.setChildren(dTreeList4Machine);
                    dTreeList4SecDept.add(dTree4SecDept);
                }
            });
            dTree.setChildren(dTreeList4SecDept);

            dTreeList.add(dTree);
        });
        //5.过滤数据
        CollUtil.forEach(dTreeList.iterator(),(dTree,index)->{
            if(CollUtil.isEmpty(dTree.getChildren())) {
                dTree.setLast(true);
                dTree.setDisabled(true);
            } else {
                CollUtil.forEach(dTree.getChildren().iterator(),(dTree4SecDept,index2)->{
                    if(CollUtil.isEmpty(dTree4SecDept.getChildren())){
                        dTree4SecDept.setLast(true);
                        dTree4SecDept.setDisabled(true);
                    }
                });
            }
        });




        return dTreeList;
    }

    @Override
    public List<DTree> getAll4UsmBt() {
        List<DTree> dTreeList = CollUtil.list(false);
        // 1.获取所有第一级制造部
        List<String> topDeptPermisList=CollUtil.list(false);
        topDeptPermisList = StpUtil.getPermissionList(StpUtil.getLoginIdAsString());
        if(topDeptPermisList.size()!=1) return null;
        if((!topDeptPermisList.get(0).equals("146")) && (!topDeptPermisList.get(0).equals("1")))
            return null;


        LambdaQueryWrapper<DepartmentsPO> wrapper = new QueryWrapper<DepartmentsPO>().lambda();

        wrapper .eq(DepartmentsPO::getParentID,0)   //父ID=0
                .eq(DepartmentsPO::getDepartmentID,146)      //自己的ID>10
                .orderByAsc(DepartmentsPO::getDepartmentName);

        List<DepartmentsPO> topDeptList = departmentsPOMapper.selectList(wrapper);
        if(CollUtil.isEmpty(topDeptList)) return null;
        List<Integer> topDeptIDList = CollUtil.list(false);
        CollUtil.forEach(topDeptList,(topDeptPO,index)->{
            topDeptIDList.add(topDeptPO.getDepartmentID());
        });

        // 2.获取所有的第二级制造工程
        LambdaQueryWrapper<DepartmentsPO> wrapper2 = new QueryWrapper<DepartmentsPO>().lambda();
        wrapper2.in(DepartmentsPO::getParentID,topDeptIDList);
        List<DepartmentsPO> secDeptList = departmentsPOMapper.selectList(wrapper2);
        if(CollUtil.isEmpty(secDeptList)) return null;
        List<Integer> secDeptIDList = CollUtil.list(false);
        CollUtil.forEach(secDeptList.iterator(),(secDeptPO,index2)->{
            secDeptIDList.add(secDeptPO.getDepartmentID());
        });

        //3.获取所有的设备
        LambdaQueryWrapper<MachinePO> wrapper3 = new LambdaQueryWrapper<>();
        wrapper3.in(MachinePO::getSecDeptID,secDeptIDList);
        List<MachinePO> machineList = machinePOMapper.selectList(wrapper3);
        if(CollUtil.isEmpty(machineList)) return null;

        //4.组装数据
        CollUtil.forEach(topDeptList.iterator(),(topDeptPO,index)->{
            DTree dTree = new DTree();
            // 4.1 第一层,制造部数据
            dTree.setId(topDeptPO.getDepartmentID().toString());
            dTree.setParentId("0");
            dTree.setTitle(topDeptPO.getDepartmentName());
            dTree.setLast(false);
            dTree.setDisabled(!topDeptPO.getEnabled());
            // 4.2 第二层
            List<DTree> dTreeList4SecDept = CollUtil.list(false);
            CollUtil.forEach(secDeptList.iterator(),(secDeptPO,index2)->{
                if(topDeptPO.getDepartmentID().equals(secDeptPO.getParentID())){
                    DTree dTree4SecDept = new DTree();
                    dTree4SecDept.setId(secDeptPO.getDepartmentID().toString());
                    dTree4SecDept.setParentId(topDeptPO.getDepartmentID().toString());
                    dTree4SecDept.setTitle(secDeptPO.getDepartmentName());
                    dTree4SecDept.setLast(false);
                    dTree4SecDept.setDisabled(!secDeptPO.getEnabled());
                    //4.3 第三层
                    List<DTree> dTreeList4Machine = CollUtil.list(false);
                    CollUtil.forEach(machineList.iterator(),(machinePO,index3)->{
                        if(secDeptPO.getDepartmentID().equals(machinePO.getSecDeptID())){
                            DTree dTree4Machine = new DTree();
                            dTree4Machine.setId(machinePO.getMachineID().toString());
                            dTree4Machine.setParentId(secDeptPO.getDepartmentID().toString());
                            dTree4Machine.setTitle(machinePO.getMachineNo());
                            dTree4Machine.setLast(true);
                            dTree4Machine.setDisabled(!machinePO.getEnabled());
                            dTreeList4Machine.add(dTree4Machine);
                        }
                    });
                    dTree4SecDept.setChildren(dTreeList4Machine);
                    dTreeList4SecDept.add(dTree4SecDept);
                }
            });
            dTree.setChildren(dTreeList4SecDept);

            dTreeList.add(dTree);
        });
        //5.过滤数据
        CollUtil.forEach(dTreeList.iterator(),(dTree,index)->{
            if(CollUtil.isEmpty(dTree.getChildren())) {
                dTree.setLast(true);
                dTree.setDisabled(true);
            } else {
                CollUtil.forEach(dTree.getChildren().iterator(),(dTree4SecDept,index2)->{
                    if(CollUtil.isEmpty(dTree4SecDept.getChildren())){
                        dTree4SecDept.setLast(true);
                        dTree4SecDept.setDisabled(true);
                    }
                });
            }
        });




        return dTreeList;
    }

    @Override
    public List<DTree> getAll4UsmCd() {
        List<DTree> dTreeList = CollUtil.list(false);
        // 1.获取所有第一级制造部
        List<String> topDeptPermisList=CollUtil.list(false);
        topDeptPermisList = StpUtil.getPermissionList(StpUtil.getLoginIdAsString());
        if(topDeptPermisList.size()!=1) return null;
        if((!topDeptPermisList.get(0).equals("147")) && (!topDeptPermisList.get(0).equals("1")))
            return null;


        LambdaQueryWrapper<DepartmentsPO> wrapper = new QueryWrapper<DepartmentsPO>().lambda();

        wrapper .eq(DepartmentsPO::getParentID,0)   //父ID=0
                .eq(DepartmentsPO::getDepartmentID,147)      //自己的ID>10
                .orderByAsc(DepartmentsPO::getDepartmentName);

        List<DepartmentsPO> topDeptList = departmentsPOMapper.selectList(wrapper);
        if(CollUtil.isEmpty(topDeptList)) return null;
        List<Integer> topDeptIDList = CollUtil.list(false);
        CollUtil.forEach(topDeptList,(topDeptPO,index)->{
            topDeptIDList.add(topDeptPO.getDepartmentID());
        });

        // 2.获取所有的第二级制造工程
        LambdaQueryWrapper<DepartmentsPO> wrapper2 = new QueryWrapper<DepartmentsPO>().lambda();
        wrapper2.in(DepartmentsPO::getParentID,topDeptIDList);
        List<DepartmentsPO> secDeptList = departmentsPOMapper.selectList(wrapper2);
        if(CollUtil.isEmpty(secDeptList)) return null;
        List<Integer> secDeptIDList = CollUtil.list(false);
        CollUtil.forEach(secDeptList.iterator(),(secDeptPO,index2)->{
            secDeptIDList.add(secDeptPO.getDepartmentID());
        });

        //3.获取所有的设备
        LambdaQueryWrapper<MachinePO> wrapper3 = new LambdaQueryWrapper<>();
        wrapper3.in(MachinePO::getSecDeptID,secDeptIDList);
        List<MachinePO> machineList = machinePOMapper.selectList(wrapper3);
        if(CollUtil.isEmpty(machineList)) return null;

        //4.组装数据
        CollUtil.forEach(topDeptList.iterator(),(topDeptPO,index)->{
            DTree dTree = new DTree();
            // 4.1 第一层,制造部数据
            dTree.setId(topDeptPO.getDepartmentID().toString());
            dTree.setParentId("0");
            dTree.setTitle(topDeptPO.getDepartmentName());
            dTree.setLast(false);
            dTree.setDisabled(!topDeptPO.getEnabled());
            // 4.2 第二层
            List<DTree> dTreeList4SecDept = CollUtil.list(false);
            CollUtil.forEach(secDeptList.iterator(),(secDeptPO,index2)->{
                if(topDeptPO.getDepartmentID().equals(secDeptPO.getParentID())){
                    DTree dTree4SecDept = new DTree();
                    dTree4SecDept.setId(secDeptPO.getDepartmentID().toString());
                    dTree4SecDept.setParentId(topDeptPO.getDepartmentID().toString());
                    dTree4SecDept.setTitle(secDeptPO.getDepartmentName());
                    dTree4SecDept.setLast(false);
                    dTree4SecDept.setDisabled(!secDeptPO.getEnabled());
                    //4.3 第三层
                    List<DTree> dTreeList4Machine = CollUtil.list(false);
                    CollUtil.forEach(machineList.iterator(),(machinePO,index3)->{
                        if(secDeptPO.getDepartmentID().equals(machinePO.getSecDeptID())){
                            DTree dTree4Machine = new DTree();
                            dTree4Machine.setId(machinePO.getMachineID().toString());
                            dTree4Machine.setParentId(secDeptPO.getDepartmentID().toString());
                            dTree4Machine.setTitle(machinePO.getMachineNo());
                            dTree4Machine.setLast(true);
                            dTree4Machine.setDisabled(!machinePO.getEnabled());
                            dTreeList4Machine.add(dTree4Machine);
                        }
                    });
                    dTree4SecDept.setChildren(dTreeList4Machine);
                    dTreeList4SecDept.add(dTree4SecDept);
                }
            });
            dTree.setChildren(dTreeList4SecDept);

            dTreeList.add(dTree);
        });
        //5.过滤数据
        CollUtil.forEach(dTreeList.iterator(),(dTree,index)->{
            if(CollUtil.isEmpty(dTree.getChildren())) {
                dTree.setLast(true);
                dTree.setDisabled(true);
            } else {
                CollUtil.forEach(dTree.getChildren().iterator(),(dTree4SecDept,index2)->{
                    if(CollUtil.isEmpty(dTree4SecDept.getChildren())){
                        dTree4SecDept.setLast(true);
                        dTree4SecDept.setDisabled(true);
                    }
                });
            }
        });




        return dTreeList;
    }
}
